package physics.globalforce;

import physics.Assembly;
import physics.EnvironmentSingleton.EnvironmentalForce;
import physics.Force;
import physics.component.Mass;


/**
 * Global gravitational force.
 *
 * @author Kevin Gao, Connor Gordon
 *
 */
public class Gravity extends GlobalForce {

    private double myGravityDirection = Mass.DOWN;
    private double myGravityMagnitude = 1;

    /**
     * Default constructor.
     */
    public Gravity () {
        super(EnvironmentalForce.GRAVITY);
    }

    /**
     * Constructs a new gravity force with given direction and magnitude.
     *
     * @param dir Angle in degrees
     * @param mag Magnitude of force
     */
    public Gravity (final double dir, final double mag) {
        super(EnvironmentalForce.GRAVITY);
        setGlobalGravity(dir, mag);
    }

    @Override
    protected final Force getCalculatedForce (final Mass target,
            final Assembly asm) {
        Force result = new Force(myGravityDirection, myGravityMagnitude);
        result.scale(1.0 / target.getMass());
        return result;
    }

    /**
     * Sets Global Gravity parameters.
     *
     * @param mag Magnitude of gravity
     * @param dir Direction of gravity (angle in degrees)
     */
    public final void setGlobalGravity (final double dir, final double mag) {
        myGravityDirection = dir;
        myGravityMagnitude = mag;
    }

}
